package top.soulblack.purchasesale.mapper;


import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import top.soulblack.purchasesale.model.DTO.GoodDTO;
import top.soulblack.purchasesale.model.Goods;
import top.soulblack.purchasesale.model.VO.GoodsToIdVO;
import top.soulblack.purchasesale.model.VO.GoodsToQueryVO;
import top.soulblack.purchasesale.model.form.OrderForm;

import java.util.List;

/**
 * create by 小川
 */
@Mapper
public interface GoodsMapper {
    int deleteByPrimaryKey(String name);

    int insert(Goods record);

    int insertSelective(Goods record);

    Goods selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Goods record);

    int updateByPrimaryKey(Goods record);

    List<GoodsToQueryVO> selectGoodListToQuery();

    List<GoodsToQueryVO> selectSKUToQuery();

    List<GoodDTO> selectGoodsOptionForOrder();

    List<GoodDTO> selectGoodsByBarCode(@Param("barCode") String barCode);

    List<GoodsToIdVO> selectFromName(@Param("goodsName") String goodsName);

    List<GoodsToIdVO> selectToId();

    List<GoodsToIdVO> selectClear();


    @Select(" SELECT * FROM goods WHERE goods.bar_code= #{goodsBarCode} and goods.size =#{sizeId}  and goods.color =#{colorId}")
    Goods selectSKUBycolorIdAndSizeIdAndBarCode(@Param("goodsBarCode")String goodsBarCode,
                                                      @Param("sizeId") Integer sizeId,
                                                      @Param("colorId") Integer colorId);

    List<GoodsToIdVO> selectClearFromName(@Param("goodsName") String goodsName);


    @Select("select * from goods order by sort")
    List<Goods> selectAll();

    @Insert("insert into goods (name,goods_number, bar_code,only_bar_code, img_url,purchase_price,wholesale_price,sale_price," +
            "recommend_price, color,size,gender,classify,brand,material,season,style,unit,backing_pag,stock_min,stock_max," +
            "remark,sort,status) values (#{name}, #{goodsNumber}, #{barCode},#{onlyBarCode}, #{imgUrl}, #{purchasePrice}, #{wholesalePrice}, #{salePrice}," +
            " #{recommendPrice}, #{color}, #{size}, #{gender}, #{classify}, #{brand}, #{material}, #{season}, #{style}, #{unit}, #{backingPag}, #{stockMin}," +
            " #{stockMax}, #{remark}, #{sort}, #{status})")
    void addGoods(Goods goods);

    @Select("select * from goods where name = #{goodsName} order by sort")
    List<Goods> selectForName(@Param("goodsName") String goodsName);

    @Select("select count(*) from goods where name = #{name}")
    int existGoods(String name);

    @Select("select count(*) from goods where bar_code = #{bar}")
    int exist_bar(String bar);

    @Select("select count(*) from goods where goods_number = #{goodsNumber}")
    int exist_goods_number(String goods_number);

    @Select("select count(*) from goods where only_bar_code = #{only_bar}")
    int exist_only_bar(String only_bar);

}
